package com.instpower.things.service.impl;

import com.instpower.things.config.PropertyUtil;
import com.instpower.things.entity.ResponseMQ;
import com.instpower.things.helper.DateUtil;
import com.instpower.things.instpower.Context;
import com.instpower.things.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MessageServiceImpl implements MessageService {


    @Override
    public void send(String cabinetSn,String batterySn,boolean isReturn, int slotNum, String orderNo, int requestType, int status, String remark) {
        RabbitTemplate rabbitTemplate = Context.getBean("rabbitTemplate");
        ResponseMQ mq = new ResponseMQ();
        mq.setCabinetSn(cabinetSn);
        mq.setSlotNum(slotNum);
        mq.setOrderNo(orderNo);
        mq.setRequestType(requestType);
        mq.setStatus(status);
        mq.setBatterySn(batterySn);
        mq.setOrderTime(DateUtil.formatNow(PropertyUtil.getProperty("things.timeZone", "Asia/Shanghai")));
        log.info("机柜给server回复消息,消息是:{}",mq);
        if (isReturn) {
            rabbitTemplate.convertAndSend("return_queue_key", mq);
        } else {
            rabbitTemplate.convertAndSend("rent_response_queue_key", mq);
        }
    }
}
